package com.soundShape.utils
{
	import mx.effects.Parallel;
	import mx.events.EffectEvent;
	import mx.events.FlexEvent;
	
	import spark.components.Image;
	import spark.effects.Fade;
	import spark.effects.Resize;
	
	public class SoundWave extends Image
	{
		
		
		
		[Bindable]
		[Embed(source="assets/images/shapeOfSound.png")]
		private var shapeOfSound:Class;
		
		private var _startDelay:String;
		private var _radius:String;
		private var _finalAlpha:String;
		private var _duration:String;
		private var resize:Resize
		private var fade:Fade;
		
		public function SoundWave()
		{
			super();
			this.source = shapeOfSound;
			this.height = 0;
			this.width = 0;
			this.alpha = 0;
			this.addEventListener(FlexEvent.CREATION_COMPLETE, handleCreationComplete);
		}
		
		public function get duration():String
		{
			return _duration;
		}

		public function set duration(value:String):void
		{
			_duration = value;
		}

		public function get finalAlpha():String
		{
			return _finalAlpha;
		}

		public function set finalAlpha(value:String):void
		{
			_finalAlpha = value;
		}

		protected function handleCreationComplete(flexEvent:FlexEvent):void
		{
			//doParallel();
		}
		
		public function get radius():String
		{
			return _radius;
		}

		public function set radius(value:String):void
		{
			_radius = value;
		}

		public function get startDelay():String
		{
			return _startDelay;
		}

		public function set startDelay(value:String):void
		{
			_startDelay = value;
		}

		private function doParallel():void
		{
			resize = new Resize();
			resize.target = this;
			resize.heightFrom = 0;
			resize.heightTo = parseInt(radius);
			resize.widthFrom = 0;
			resize.widthTo = parseInt(radius);
			
			fade = new Fade();
			fade.target = this;
			fade.alphaFrom = 0;
			fade.alphaTo = parseInt(finalAlpha) / 100;
			
			var parallel:Parallel = new Parallel();
			parallel.children = [resize, fade];
			parallel.duration = parseInt(duration);
			parallel.startDelay = parseInt(startDelay);
			parallel.play();
		}
		
		public function reRun():void
		{
			this.alpha = 0;
			this.height = 0;
			this.width = 0;
			doParallel();
		}
		
	}
}